/* 后台路由 */
const Router = require('koa-router') // koa 路由

const {
  user,
  environment,
  inspect,
  service,
  serviceGroup,
  pod,
  app,
  monitor
} = require('../controller')
const apiRouter = new Router({ prefix: '/api' })
exports.api = apiRouter.post('/login', user.login)
.get('/auth/permissions', user.permissions)
.get('/environment', environment.environment) // 环境
.post('/addEnvironment', environment.addEnvironment) // 添加环境
.post('/common/importEnvironment', environment.environmentImport)
.get('/common/:environmentId/export', environment.environmentExport)
.get('/environments/:environmentId/environmentandresourcelimit', environment.environmentDetail)
.all('/environments/:environmentId', environment.environmentEdit)
.get('/environments/:environmentId/events', environment.events)
.get('/service', service.service) // 服务
.get('/logout', user.logout)
// 巡检
.get('/inspect/config/search', inspect.configSearch)
.post('/inspect/config/update', inspect.configUpdate)
.post('/inspect/doJob', inspect.doJob)
.get('/inspect/item/search', inspect.itemSearch)
.get('/inspect/object/searchObject', inspect.searchObject)
.get('/inspect/record', inspect.record)
.get('/inspect/type', inspect.inspectType)
.get('/inspect/lastRecord', inspect.lastRecord)
.get('/inspect/recordPanel', inspect.recordPanel)
.get('/inspect/logTypeList', inspect.logTypeList)
.get('/inspect/config/findParentType', inspect.getInspectType)
.get('/env/getDomain', environment.getDomain)
.get('/getMonitor', environment.getMonitor)
.get('/environment/info', environment.environmentInfo)
.post('/serviceGroup/add', serviceGroup.serviceGroupAdd)
.put('/serviceGroup/edit', serviceGroup.serviceGroupEdit)
.all('/environments/:environmentId/pods/:podId', service.pod)
.post('/service/add', environment.serviceAdd)
.get('/serviceGroup/info', serviceGroup.info)
.get('/serviceGroup/services', serviceGroup.services)
.get('/service/info', service.getServiceInfo)
// 容器操作
.get('/getPods', pod.getPods)
.patch('/pod/add', pod.add)
.delete('/pod/delete', pod.delete)
.get('/jvm/threadDump/:environmentId/:podId', pod.threadDumpDownload)
.get('/jvm/heapDump/:environmentId/:podId', pod.heapDumpDownload)
.get('/jvm/heapUsage/:environmentId/:podId', pod.heapUsageDownload)
.get('/jvm/heapDump/checkDownCount', pod.heapDumpDownloadCount)

.all('/environments/:environmentId/groups/:groupId', serviceGroup.groupMani)
.all('/environments/:environmentId/configmaps', environment.configSet)
.all('/environments/:environmentId/configmaps/:configId', environment.configSet)
.all('/environments/:environmentId/persistentvolumeclaims', environment.pvc)
.all('/environments/:environmentId/persistentvolumeclaims/:pvcId', environment.pvc)
.all('/environments/:environmentId/groups/:groupId/services/:serviceId', service.serviceMani)
.post('/environments/:environmentId/groups/:groupId/services/:serviceId/start', service.serviceStart)
.post('/environments/:environmentId/groups/:groupId/services/:serviceId/stop', service.serviceStop)
.delete('/environments/:environmentId/groups/:groupId/services/:serviceId/reboot', service.serviceReboot)
// 访问权
.all('/environments/:environmentId/ingresses', environment.accessRight)
.all('/environments/:environmentId/ingresses/:ingress', environment.accessRight)
.get('/environments/:environmentId/groups/getByServiceId/:serviceId', environment.getServiceGroupByServiceId)
.get('/environments/:environmentId/serviceList', service.list)
.all('/environments/:environmentId/dockerhubs', environment.dockerhub)
.all('/environments/:environmentId/dockerhubs/:docerId', environment.dockerhub)
.get('/harbor/images/:url/:env/:server/tags', service.imageUpdate)
.get('/environments/:environmentId/appstore/apptemplates', app.list)
.all('/environments/:environmentId/appstore/apptemplates/:shopId', app.shop)
// 监控告警
.get('/scheduler-job/alert', monitor.list)
.get('/scheduler-job/alert/metaInfo', monitor.ruleInfo)
.post('/scheduler-job/alert', monitor.addAlert)
.all('/scheduler-job/alert/:alertName', monitor.alertDetail)
.put('/scheduler-job/alert/update/:alertName', monitor.updateAlert)
.get('/scheduler-job/alert/initMetaList', monitor.oneKeyList)
.put('/scheduler-job/alert/init/:emails', monitor.oneKeyAlert)
.get('/scheduler-job/alert/alertRecord/get', monitor.historyList)
.post('/scheduler-job/alert/alertRecord/changeStatus', monitor.changeStatus)
